package AppConfig

import (
	"fmt"
	"github.com/spf13/viper"
	"path/filepath"
	"runtime"
)

type AppConfig struct {
	Mysql Mysql
	Redis Redis
}
type Mysql struct {
	User     string
	Password string
	Host     string
	Port     string
	Database string
}
type Redis struct {
	Password string
	Host     string
	Port     string
}

var AppConf AppConfig

func ConfInit() {
	_, filename, _, _ := runtime.Caller(0)
	dir := filepath.Dir(filename)

	// 构建配置文件的绝对路径
	configPath := filepath.Join(dir, "conf.yaml")
	viper.SetConfigFile(configPath)
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	err = viper.Unmarshal(&AppConf)
	if err != nil {
		panic(err)
	}
	fmt.Println(AppConf)
}
